package ee.ttu.controller;

/**
 * Created by Kristina Nogteva on 20.03.2015.
 */
/*
import java.util.ArrayList;

import javax.servlet.http.HttpServletResponse;


import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; */
import ee.ttu.model.Kasutaja;
import ee.ttu.model.Oppejoud;
import ee.ttu.model.Tudeng;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import ee.ttu.exceptions.NoPermissionException; 
import ee.ttu.frontend.service.UserService;



//import ee.ttu.model.Kasutaja;
import java.util.List;


@RestController
public class UserController {

	@Autowired
	UserService userService;
	
	final static Logger logger = Logger.getLogger(UserController.class);
	/**
	 * Konkreetse kasutaja andmete vaatamine (tudeng ja õppejõud)
	 * Kõikide tudengite andmete kuvamine
	 *  Kõikide õppejõudude andmete kuvamine
	 *
	 */


	@RequestMapping(value = "/getstudent", method = RequestMethod.GET,produces = "application/json")
	 public @ResponseBody Tudeng getTudeng(@RequestParam long userId) {
		logger.info("Invoking getstudent: " + userId);
		Tudeng tudeng = userService.getTudeng(userId);
		return tudeng;
	}

	@RequestMapping(value = "/getteacher", method = RequestMethod.GET,produces = "application/json")
	public @ResponseBody Oppejoud getOppejoud(@RequestParam long userId) {
		logger.info("Invoking getteacher: " + userId);
		Oppejoud oppejoud = userService.getOppejoud(userId);
		return oppejoud;
	}

	@RequestMapping(value = "/getstudents", method = RequestMethod.GET,produces = "application/json")
	public @ResponseBody List<Tudeng> getTudengid(){
		logger.info("Invoking getstudents");
		List<Tudeng> tudengid = userService.getTudengid();
		return tudengid;

	}

	@RequestMapping(value = "/getteachers", method = RequestMethod.GET,produces = "application/json")
	public @ResponseBody List<Oppejoud> getKoikoppejoud(){
		logger.info("Invoking getteachers");
		List<Oppejoud> koikoppejoud = userService.getKoikoppejoud();
		return koikoppejoud;

	}
	
	@RequestMapping(value = "/getuser", method = RequestMethod.GET,produces = "application/json")
	public @ResponseBody Kasutaja getUsers (@RequestParam long userId) {
		
		Kasutaja kasutajad = userService.getUser(userId);
		
		return kasutajad;
	} 
	


/*
	@RequestMapping(value = "/registration", method = RequestMethod.POST,produces = "application/json")
	public void saveNewUser(@RequestBody Kasutaja kasutaja, Model model) {
		
		userService.saveNewUser(kasutaja, model);
	}

	@RequestMapping(value = "/updateUser", method = RequestMethod.PUT,produces = "application/json")
	public void updateUser(@RequestBody Kasutaja uusKasutaja,
			@RequestParam("username") String username,
			@RequestParam("password") String password, Model model)
			throws NoPermissionException {

		userService.updateUser(uusKasutaja, username, password, model);

	}

	
	
	

	@RequestMapping(value = "/user", method = RequestMethod.GET,produces = "application/json")
	public @ResponseBody Kasutaja getUser(
			@RequestParam("usersUsername") String usersUsername,
			@RequestParam("username") String username,
			@RequestParam("password") String password) throws NoPermissionException {

		Kasutaja kasutaja = userService.getUser(usersUsername, username, password);
		
		return kasutaja;
	}
	
	@RequestMapping(value = "/activate", method = RequestMethod.PUT,produces = "application/json")
	public void activateUser(
			@RequestParam("usersUsername") String usersUsername,
			@RequestParam("username") String username,
			@RequestParam("password") String password, Model model) throws NoPermissionException  {
		
		userService.activateUser(usersUsername, username, password, model);
	}
	
	@RequestMapping(value = "/deactivate", method = RequestMethod.PUT,produces = "application/json")
	public void deactivateUser(
			@RequestParam("usersUsername") String usersUsername,
			@RequestParam("username") String username,
			@RequestParam("password") String password,Model model) throws NoPermissionException  {
		
		userService.deactivateUser(usersUsername, username, password, model);
	}
	*/
}
